package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Combo;
import com.ruoyi.system.mapper.ComboMapper;
import com.ruoyi.system.mapper.CustomerMapper;
import com.ruoyi.system.mapper.PhotographerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CustomerPhotoMapper;
import com.ruoyi.system.domain.CustomerPhoto;
import com.ruoyi.system.service.ICustomerPhotoService;

/**
 * 客照关系Service业务层处理
 * 
 * @author Eugene
 * @date 2023-04-15
 */
@Service
public class CustomerPhotoServiceImpl implements ICustomerPhotoService 
{
    @Autowired
    private CustomerPhotoMapper customerPhotoMapper;

    @Autowired
    private ComboMapper comboMapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Autowired
    private PhotographerMapper photographerMapper;

    /**
     * 查询客照关系
     * 
     * @param id 客照关系主键
     * @return 客照关系
     */
    @Override
    public CustomerPhoto selectCustomerPhotoById(Long id)
    {
        return customerPhotoMapper.selectCustomerPhotoById(id);
    }

    /**
     * 查询客照关系列表
     * 
     * @param customerPhoto 客照关系
     * @return 客照关系
     */
    @Override
    public List<CustomerPhoto> selectCustomerPhotoList(CustomerPhoto customerPhoto)
    {
        List<CustomerPhoto> list = customerPhotoMapper.selectCustomerPhotoList(customerPhoto);
//        CustomerPhoto cp = new CustomerPhoto();
        //按照客照关系表中的combo_id查询combo表中的combo_name
        for (CustomerPhoto customerPhoto2 : list) {
            customerPhoto2.setComboName(comboMapper.selectComboById(customerPhoto2.getComboId()).getComboName());
        }

        //按照客照关系表中的customer_id查询customer表中的customer_name
        for (CustomerPhoto customerPhoto2 : list) {
            customerPhoto2.setCustomerName(customerMapper.selectCustomerById(customerPhoto2.getCustomerId()).getName());
        }

        //按照客照关系表中的photographer_id查询photographer表中的photographer_name
        for (CustomerPhoto customerPhoto2 : list) {
            customerPhoto2.setPhotographerName(photographerMapper.selectPhotographerById(customerPhoto2.getPhotographerId()).getName());
        }

        return list;
    }

    /**
     * 新增客照关系
     * 
     * @param customerPhoto 客照关系
     * @return 结果
     */
    @Override
    public int insertCustomerPhoto(CustomerPhoto customerPhoto)
    {
        customerPhoto.setCreateTime(DateUtils.getNowDate());
        return customerPhotoMapper.insertCustomerPhoto(customerPhoto);
    }

    /**
     * 修改客照关系
     * 
     * @param customerPhoto 客照关系
     * @return 结果
     */
    @Override
    public int updateCustomerPhoto(CustomerPhoto customerPhoto)
    {
        customerPhoto.setUpdateTime(DateUtils.getNowDate());
        return customerPhotoMapper.updateCustomerPhoto(customerPhoto);
    }

    /**
     * 批量删除客照关系
     * 
     * @param ids 需要删除的客照关系主键
     * @return 结果
     */
    @Override
    public int deleteCustomerPhotoByIds(Long[] ids)
    {
        return customerPhotoMapper.deleteCustomerPhotoByIds(ids);
    }

    /**
     * 删除客照关系信息
     * 
     * @param id 客照关系主键
     * @return 结果
     */
    @Override
    public int deleteCustomerPhotoById(Long id)
    {
        return customerPhotoMapper.deleteCustomerPhotoById(id);
    }
}
